// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import YDUI from 'vue-ydui'
import KeyBoard from 'vue-num-keyboard';
import 'vue-num-keyboard/style.css'
Vue.use(YDUI);
import "vue-ydui/dist/ydui.rem.css";
import "vue-ydui/dist/ydui.flexible";
import "vue-ydui/dist/ydui.base.css";
import VueResource from 'vue-resource'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
Vue.use(VueResource)
Vue.config.productionTip = false
    //封装的请求数据的组件
import Utils from "./utils";
Vue.use(Utils);
Vue.use(KeyBoard);
import axios from 'axios'
/* eslint-disable no-new */

//图片懒加载 

import Mint from 'mint-ui';
Vue.use(Mint);
import 'mint-ui/lib/style.css';

router.beforeResolve((to, from, next) => {
    // window.document.title=to.meta.title //title

    // let token = to.query.login_token ? to.query.login_token : null;
    // let r_token = to.query.token ? to.query.token : null;
    // let id = to.query.id ? to.query.id : null;
    // let shop = to.query.shop ? to.query.shop : null;
    // let openid = to.query.openid ? to.query.openid : null;
    // let token = 'MSM1MCM4Njk5';

    // if (r_token) {
    //     localStorage.setItem("token", r_token);
    // }
    // if (openid) {
    //     localStorage.setItem("openid", openid);
    // }

    // if (shop) {
    //     localStorage.setItem("shop", shop);
    // }


    // if (token && id) {
    //     localStorage.setItem("mytoken", token);
    //     localStorage.setItem("myid", id);
    // }
    //  next();
    // token = localStorage.getItem("mytoken");

    
    let type = to.query.type ? to.query.type : null;

    let openid = to.query.openid ? to.query.openid : null;
    let shopid = to.query.shopid ? to.query.shopid : null;
    let status = to.query.status ? to.query.status : null;
    let token = to.query.token ? to.query.token : null;
    let id = to.query.r_id ? to.query.r_id : null;
    let up_id = to.query.up_id ? to.query.up_id : null;
    if (openid) {
        localStorage.setItem("openid", openid);
    }
    if (shopid) {
        localStorage.setItem("shopid", shopid);
    }
    if (status) {
        localStorage.setItem("status", status);
    }
    if (token) {
        localStorage.setItem("mytoken", token);
    }
    if (id) {
        localStorage.setItem("myid", id);
    }
    if (type) {
        localStorage.setItem("type", type);
    }
    if (up_id) {
        localStorage.setItem("up_id", up_id);
    } 
    // if (status == 0) {
    //     next('/registered')
    // } else if(type==1 && status == 1){
    //     next('/')
    // }
    //  else {
    //     next()
    // }


    // if (status == 0) {
    //     next('/registered')
    // } else {
    //     next()
    // }

    // if (status == 0) {
    //     next('/registered')
    // } else {
    //     next()
    // }

    if(type == 1){
        if(status == 0){ 
            next('/registered1')
        }else{
            next() 
        } 
    }else{
        if(status == 0){
            next('/registered')
        }else{
            next() 
        }
    }
});

//超时时间
axios.defaults.timeout = 5000
    //   // http请求拦截器
    // axios.interceptors.request.use(config => {
    //       let token = localStorage.getItem('mytoken'); //------
    //       if (!token) {
    //           // return config
    //           token = 'dG9rZW4tMS0w'
    //       }
    //       config.headers['Authorization'] = token; //-------
    //       return config
    //   }, error => {
    //       return Promise.reject(error)
    //   })
    //   // http响应拦截器
axios.interceptors.response.use(res => { // 响应成功关闭loading
    return res.data
}, error => {
    return Promise.reject(error)
})

new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
})